
package escaleras.pkginterface;

import java.awt.EventQueue;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JProgressBar;


public class HiloProcesos extends Thread{
    JProgressBar barra;
    private static int retraso=5;
    
    public HiloProcesos(JProgressBar unaBarra){
        barra=unaBarra;
    }
    
    @Override
    public void run() {
        int maximo = barra.getMaximum();
        int minimo = barra.getMinimum();

        Runnable ejecutor = new Runnable() {
            @Override
            public void run() {
                int valorActual = barra.getValue();
                barra.setValue(valorActual + 1);
            }
        };
        for (int i = minimo; i < maximo; i++) {

            try {
                EventQueue.invokeAndWait(ejecutor);
                Thread.sleep(retraso);
            } catch (InterruptedException ex) {
            } catch (InvocationTargetException ex) {
                
            }
        }
        barra.setValue(barra.getMinimum());
    }    
}
 